import React from 'react'
import axios from 'axios'

export default function App() {

  const handleClick = async () => {
    try {
       // 不能直接请求跨域的目标接口
      // const response = await axios.get('http://localhost:4000/search/users?q=zxf', {
      // 当前前台项目的地址 => webpack-dev-server => 404 => 代理服务器将请求转发http://localhost:4000上去
      const response = await axios.get('/search/users', {  
        params: {q: 're'}
      })
      console.log(response.data)
    } catch (error) {
      alert(error.message)
    }
  }

  return (
    <div>
      <button onClick={handleClick}>请求获取数据</button>
    </div>
  )
}
